﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DB;

namespace CVTH.Helper
{
    public class GroupHelper
    {

        public int count = 0;
        public int countgroup()
        {
            return count;
        }

        public IQueryable select(int maximumRows, int startRowIndex)
        {
            var db = DCFactory.GetDataContext<DBDataContext>();
            var query = from v in db.Groups
                        select v;
            count = query.Count();
            return query.Skip(startRowIndex).Take(maximumRows);
        }
        public IQueryable selectAll()
        {
            var db = DCFactory.GetDataContext<DBDataContext>();
            return db.Groups;
        }

        public static int InsertGroup(Group g)
        {
            var db = DCFactory.GetDataContext<DBDataContext>();
            db.Groups.InsertOnSubmit(g);
            db.SubmitChanges();
            return g.GroupId;
        }

        public static bool DeleteGroup(int groupid)
        {
            var db = DCFactory.GetDataContext<DBDataContext>();
            var g = db.Groups.SingleOrDefault(v => v.GroupId == groupid);
            if (g != null)
            {
                db.Groups.DeleteOnSubmit(g);
                return true;
            }
            return false;
        }

    }
}